import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/29 15:25
 * @description 思路：因为nums[i] < 2 ^ maximumBit，所以整数数组异或最大值为2^maximumBit - 1
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2, 3, 4, 7};
        solution.getMaximumXor(nums, 3);
    }
    public int[] getMaximumXor(int[] nums, int maximumBit) {
        int n = nums.length;
        int max = (1 << maximumBit) - 1;
        int[] ans = new int[n];
        // 利用异或恒等律 0 ^ a = a, 初始值设置为0
        int or = 0;
        for (int i = 0; i < n; i++) {
            or ^= nums[i];
            ans[n - i - 1] = or ^ max;
        }
        return ans;
    }
}
